/*
* @Author: majingyu
* @Date:   2017-05-04 10:37:54
* @Last Modified by:   jingyu.ma
* @Last Modified time: 2017-08-12 17:56:01
*/

import initialState from '../state';
import { date2time } from 'common/date'

function serviceReducer(state = initialState.services, action){
    switch(action.type){
        //修改周边服务信息
        case 'EIDT_SERVICE_INFO_BEGIN':
            return Object.assign({},state,{});
        case 'EIDT_SERVICE_INFO_SUCCESS':
            let list = state.nearListList.list
            action.data.rows.map(item => {
                list.push(item);
                item.dtime = date2time(item.dtime);
            })
            return Object.assign({},state,{
                nearListList:{
                    list: list,
                    pageNo: action.data.currentPageNumber,
                    total: action.data.total
                }
            });
        //查找周边需求
        case 'EIDT_SKILL_INFO_SUCCESS':
            let skillList = state.nearSkillList.list
            action.data.rows.map(item => {
                skillList.push(item);
                item.dtime = date2time(item.dtime);
            })
            return Object.assign({},state,{
                nearSkillList:{
                    list: skillList,
                    pageNo: action.data.currentPageNumber,
                    total: action.data.total
                }
            })
        //修改服务列表
        case 'SEARCH_ALL_SEVICES_BIGIN':
            return Object.assign({}, state, {});
        case 'SEARCH_ALL_SEVICES_SUCCESS':
            return Object.assign({},state,{
                servicesCalssifyList:{
                    list: action.data,
                    pageNo: action.data.currentPageNumber,
                    total: action.data.total
                }
            })
        case 'EIDT_DEMAND_LIST_SUCCESS': 
            let newList = state.demandList.list
            action.data.rows.map(item => {
                newList.push(item);
            })
            return Object.assign({},state,{
                demandList:{
                    list: newList,
                    pageNo: action.data.currentPageNumber,
                    total: action.data.total
                }
            })
        case 'TAB_IS_SERVICESLIST':
            return Object.assign({},state, {
                activeKey: action.data
            });
        case 'TAB_IS_SKILLLIST': 
            return Object.assign({},state, {
                activeKey: action.data
            })
        case 'EDIT_CALSS_CHECK': 
            return Object.assign({},state, {
                calssListCheck: {
                    id: action.message.id,
                    name: action.message.name
                }
            })
        case 'EDIT_COURSE_DEMAND_LIST': 
            return Object.assign({},state, {
                couriersType: action.data.id,
                couriersName: action.data.name
            })
        case 'EDIT_FILTER_SERVICE_SUCCESS':
            return Object.assign({},state, {
                varfilterList:action.data.rows
            })
        case 'EDIT_SORT_SERVICE_SUCCESS':
            return Object.assign({},state, {
                sortList:action.data.rows
            })
        case 'GET_DETAIL_SUCCESS':
            return Object.assign({},state, {
                detail:action.data
            })
        case 'CHANGE_PAGE_TYPE':
            return Object.assign({},state, {
                activeKey:action.type
            })
        case 'GET_MY_INVITE_SUCCESS':
            let invite = state.getMyInviteList.list
            action.data.rows.map(item => {
                invite.push(item);
                item.dtime = date2time(item.dtime);
            })
            return Object.assign({},state,{
                getMyInviteList:{
                    list: invite,
                    pageNo: action.data.currentPageNumber,
                    total: action.data.total
                }
            })
        case 'EDIT_SKILL_MOBILE_SHOW':
            return Object.assign({}, state, {
                skillMobile: action.data
            })
        case 'EDIT_SERVICES_MOBILE_SHOW':
            return Object.assign({}, state, {
                skillMobile: action.data
            })
        default :
            return state;
    }
}

export default serviceReducer;